#include <iostream>

struct Hero
{
    std::string name;
    int age;
    std::string sex;
};

void print_heros(Hero *h, int size);
void sort_heros(Hero *h, int size);

int main()
{
    struct Hero heros[5] = {
        {"刘备", 23, "男"},
        {"关羽", 22, "男"},
        {"张飞", 20, "男"},
        {"赵云", 21, "男"},
        {"貂蝉", 19, "女"},
    };

    sort_heros(heros, 5);

    return 0;
}

void print_heros(Hero *h, int size)
{
    system("chcp 65001");
    for (size_t i = 0; i < size; i++)
    {
        std::cout << h[i].name << h[i].age << h[i].sex << std::endl;
    }
}

void sort_heros(Hero *h, int size)
{
    for (size_t i = 0; i < size; i++)
    {
        for (size_t j = 0; j < size - 1 - i; j++)
        {

            if (h[j].age > h[j + 1].age)
            {
                Hero temp = h[j];
                std::cout << temp.age << std::endl;
                h[j] = h[j + 1];
                h[j + 1] = temp;
            }
        }
    }
    print_heros(h, size);
}